package com.flying.test;

import java.util.function.BiConsumer;

public class ExceptionHandlingExample {
    public static void main(String[] args) {
        int[] nums = {1, 2, 3, 4};
        int key = 0;
        process(nums, key, wrapperLambda((v, k) -> System.out.println(v / k)));
    }

    private static void process(int[] nums, int key, BiConsumer<Integer, Integer> consumer) {
        for (int i : nums) {
            consumer.accept(i, key);
        }
    }

    private static BiConsumer<Integer, Integer> wrapperLambda(BiConsumer<Integer, Integer> consumer) {
        return (v,k) -> {
            try {
                consumer.accept(v,k);
            }
            catch (ArithmeticException ae) {
                System.out.println("Exception cauth in wrapper lambda");
            }
        };

    }
}
